package com.example.springcloudindex.web;

import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AmqpAction {

    @RequestMapping("recvWork")
    @RabbitListener(queuesToDeclare = @Queue("work"))
    void recvWork(String data){
        System.out.println("处理工作模式消息:" + data);
        //return "处理工作模式消息:" + data;
    }

    @RequestMapping("recvWork1")
    @RabbitListener(queuesToDeclare = @Queue("work"))
    void recvWork1(String data){
        System.out.println("处理工作模式消息1:" + data);
        //return "处理工作模式消息:" + data;
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value="fanout1"),
            exchange = @Exchange(value = "fanout",
                    type = ExchangeTypes.FANOUT)
    ))
    void recvFanout1(String data){
        System.out.println("处理广播模式消息1:" + data);
//        return "处理工作模式消息:" + data;
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value="direct1"),
            exchange = @Exchange(value = "direct",
                    type = ExchangeTypes.DIRECT),
            key = "order"
    ))
    void recvDierct1(String data){
        System.out.println("处理定向模式消息1:" + data);
//        return "处理工作模式消息:" + data;
    }

    //////////////////////////////////////////////////////////////////////////
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value="topic3"),
            exchange = @Exchange(value = "topic",
                    type = ExchangeTypes.TOPIC),
            key = "order.#"
    ))
    void recvTopic3(String data){
        System.out.println("处理主题模式消息3:" + data);
//        return "处理工作模式消息:" + data;
    }

}
